home *** CD-ROM | disk | FTP | other *** search
/ Hacker's Secrets 4 / Hacker's Secrets 4.iso / misc / magcard2.txt < prev    next >
Text File  |  1993-06-02  |  17KB  |  532 lines

  1.  
  2. Summary of replies to the following request:
  3.  
  4. Subject: Mag Card Swipe Reader: Need Help!
  5.  
  6. Hello, Everybody.
  7.  
  8. I just picked up one of those swipe readers for mag stripes on credit
  9. cards etc. from a surplus outfit (American Science & Surplus in
  10. Evanston, IL  708/475-8440 for those who are interested). It's not the
  11. complete unit with keypad, display, etc. but rather just the guts of the
  12. subassembly which actually reads the card (hey, what do you expect for
  13. $2.50?? ;-) Since it's surplus and taken out of a larger piece of
  14. equipment, I have no docs for this sucker. My hope is that someone else
  15. picked up one of these things to play with and has some docs or has figured
  16. out enough about it to get it to work, OR can tell me who to contact to get
  17. more info on this beast. I figured this would be a good place to ask
  18. since I've seen people asking about swipe card readers recently.
  19.  
  20. Anyway, here's a description:
  21. The unit is about 6" long, 1" wide, and maybe 2" high. It consists of a
  22. metal backing plate, attached to which is a black plastic guide channel
  23. through which you swipe the card. On one side of the plastic channel is a
  24. read head for the mag stripe; on the opposite side is a small printed circuit
  25. board.
  26.  
  27. Removing the plastic guide from the mounting plate reveals that the
  28. manufacturer is SR&D corporation of Tokyo, Japan. The model number is
  29. MCR-175-1R-0803; a serial number is also listed. The SR&D logo-lettering
  30. appears on the component side of the PC board, and on the foil side of
  31. the board the SR&D is repeated along with the code "FNC -065-1" in the
  32. upper right hand corner. The board has one IC on it (I can't easily see
  33. what the numbers are on this chip, so I'm not sure what kind it is other
  34. than a 16 pin DIP). There is a spot for another chip, an 8-pin DIP for
  35. which the screened label reads "IC2 6914", but this chip and some other
  36. resistors, capacitors, etc. are missing.
  37.  
  38. Finally, there are 5 wires coming from the assembly and terminating in a
  39. small connector similar to power supply connectors for 3.5" floppy drives.
  40. The wires are red, yellow, green, blue, and black.
  41.  
  42. I haven't hacked on this thing at all yet, since I don't know what its
  43. power requirements are or even which are power leads and which are data
  44. leads. If anyone has any information on this puppy which might help me,
  45. I'd love to hear from you! Please email me. I'll share whatever I find
  46. out with anyone who's interested.
  47.  
  48. Thanks!
  49.  
  50. ---
  51.  
  52. [Editor's Note: The following is a concatenation of the replies I received
  53. to the net.request above. After the replies I have included information
  54. which was posted to the net on how mag stripe cards are encoded (in case
  55. anyone missed it). Finally, I have included some software that I threw
  56. together to play with the card reader. This file contains all the information
  57. I have on this subject. Additions are most welcome.
  58.  
  59. You'll notice I didn't get any farther than simply reading the raw signal
  60. from the card; of the two card readers I ordered, one was completely DOA,
  61. and the other had a faulty clock output (at least I assume that it was a
  62. clock output; I was never able to read any sort of signal from that line).
  63. Someone with a fully functional reader can easily extend what I wrote to get
  64. it to decode the actual data content of the card. If you do decide to make
  65. modifications and/or extensions, I'd appreciate a copy of whatever
  66. changes you make (email to tmkk@uiuc.edu).  Enjoy!]
  67.  
  68.  
  69. Subject: Re: Mag Card Swipe Reader: Need Help!
  70.  
  71. I am truly amazed that someone else is trying to use this device!  I got
  72. mine about 2 years ago and spent some time trying to find the manufacturer.
  73. I found a listing for SR&D in the Noth America technical directory at 
  74. the public library.  I found the listing for the American sales office
  75. in Los Angeles.  I tried calling but the company had gone out of 
  76. business.  There was no listing in the local phone directory either.
  77. I then tried calling the head office in Japan, but they also had
  78. gone out of business.  I haven't seen the company listed in any recent
  79. electronics directories, so I think they really are gone.
  80.  
  81. I have spent about an hour looking at the signals on the outputs
  82. of the device.  One signal line is a /STATUS line which indicates
  83. when a card is been moved through the unit.  The other 2 lines
  84. pulse in response to a magnetic card.  I believe the IC performs
  85. Manchester decoding and clock recovery for the read channel, so one
  86. output line is DATA and the other is CLOCK.  
  87.  
  88. That is as far as I got 2 years ago and I had forgot about it until
  89. now.  If you receive any other info, please send a copy to me!
  90.  
  91. ---
  92.  
  93. >Finally, there are 5 wires coming from the assembly and terminating in a
  94. >small connector similar to power supply connectors for 3.5" floppy drives.
  95. >The wires are red, yellow, green, blue, and black.
  96.  
  97. If its anything like the units I worked with, I think you  will find
  98. that the five wires are:
  99.  
  100.         +5v
  101.     Gnd
  102.     Clock
  103.     Data
  104.     Card detected
  105.  
  106. But I don't know active levels, or which wire is what.
  107.  
  108. ---
  109.  
  110. I picked few week ago a magnetic credit card reader from a 
  111. another surplus outfit. It cost about the sam es yours. 
  112. My card reader was made by MAGTEK and was diffrent from
  113. your reder in many ways. The reader I have has 4 ICs and
  114. some of them are standard TTL chip, so I could easily 
  115. quess the power requiments (5V) and power connectors.
  116. My card reader had 6 pin connector. 
  117. I put the power to the reader and started to examine 
  118. the signals with multimeter and a little crystal
  119. earphine (my favourite electronics hacking tool).
  120. I found that output signals were something like
  121. that: data out, data clock out, data readable and
  122. and card ath the end of the reader.
  123. Then I connected the reader to the joystick port
  124. of my 386SX and made a little Turbo Pascal program
  125. for reading the card.
  126.  
  127. Spare printer port is the interface I use very often to connect
  128. diffrent hardware circuit to my computer. This time I decided
  129. to use game port beacuse it can also provide the power to the
  130. reader.
  131.  
  132. My program simply prints out the bits from the card. I have not
  133. found the way to decode the bits to corresponding numbers. The
  134. program so prints all 237 bits form the card to screen.
  135. If you have any information about data coding, I an interrested
  136. in hearing that.
  137.  
  138. Here is the meanings of the bytes in port $201:
  139. D7: 0 -> card pushed to the end of the reader
  140. D6: the read data from card
  141. D5: 0 -> data stream readable
  142. D4: the data clock
  143.  
  144. Program CardReader;
  145.  
  146. Uses Crt,Binary;
  147.  
  148. Const
  149.    gameport=$201;
  150.  
  151.  
  152. Procedure Wait_start;
  153. Begin
  154.    Repeat Until (Port[gameport] and 32)=0;
  155. End;
  156.  
  157. Function data_readable:boolean;
  158. Begin
  159.    data_readable:=((Port[gameport] and 32)=0);
  160. End;
  161.  
  162. Procedure Wait_clock;
  163. Begin
  164.    Repeat Until (Port[gameport] and 16)=0;
  165. End;
  166.  
  167. Procedure Wait_clock_end;
  168. Begin
  169.    Repeat Until (Port[gameport] and 16)=16;
  170. End;
  171.  
  172. Function data_input:byte;
  173. Begin
  174.    If (Port[gameport] and 64)=0 Then data_input:=0
  175.       Else data_input:=1;
  176. End;
  177.  
  178. Function card_at_end:boolean;
  179. Begin
  180.    card_at_end:=((Port[gameport] and 128)=0);
  181. End;
  182.  
  183. Procedure test;
  184. Begin
  185.    Wait_start;
  186.    Repeat
  187.       Writeln(ByteBin(Port[$201]));
  188.    Until keypressed;
  189. End;
  190.  
  191. Begin
  192.    ClrScr;
  193.    Wait_start;
  194.    While data_readable Do Begin
  195.       Wait_clock;
  196.       Write(data_input);
  197.       Wait_clock_end;
  198.    End;
  199.    Repeat Until KeyPressed;
  200. End.
  201.  
  202. ---
  203.  
  204. Wiring color code for the SR&D MCR-175-1R-0803 mag stripe card reader:
  205.  
  206.    Red:         +5V
  207.  Black:         Gnd
  208. Yellow:         /Card Detect
  209.  Green:         Clock (?? - non-functional on the unit I have)
  210.   Blue:         /Data
  211.  
  212.  
  213. The leading '/' indicates an active low TTL signal.
  214.  
  215.  
  216. ---
  217.  
  218.            Quick 'n Dirty guide to the enclosed reader software
  219.            ----------------------------------------------------
  220.  
  221. Hooking the SR&D MCR-175-1R-0803 card reader to your PC:
  222.  
  223. The included software is written specifically for the following
  224. configuration; if your wiring is different, you'll need to make
  225. corresponding changes to the software. Note also that the port
  226. address is hard-coded to look for LPT2's status port (at address
  227. 0x279). If you're using a different port address, be sure to change the
  228. port address value.
  229.  
  230. SR&D Wire       Printer Port Pin        Port Bit        Signal
  231. ---------       ----------------        --------        ------
  232. Yellow          11                      7               /CARD DETECT
  233. Blue            10                      6               /DATA
  234. Black           18                      N/A             (Ground)
  235.  
  236. Power to the reader was provided by a separate power supply, basically
  237. one of those black plastic DC power packs fed through a 7805 regulator
  238. chip.
  239.  
  240.  
  241. Compiling the software:
  242.  
  243. Compile SWIPE.C (using SMALL memory model), assemble SWIPEISR.ASM, and
  244. link the two together.
  245.  
  246.  
  247. Using the software:
  248.  
  249. To use SWIPE.EXE, simply hook the reader up to your LPT2: port, power it
  250. up, then run SWIPE. When you're ready, press the ENTER key, and swipe a
  251. card through the reader. The program will read the data from the card and
  252. store it in a buffer (but will not decode the data; that is left as an
  253. excercise ;-). After the card has been read, press ENTER again and the
  254. contents of the buffer will be dumped to stdout. To save the card data to
  255. a file, simply redirect SWIPE's output on the command line, e.g.
  256.  
  257. SWIPE > citibank.out
  258.  
  259. Please let me know of any changes, bug fixes, or improvements you make to
  260. this code. Send email to tmkk@uiuc.edu.
  261.  
  262. Thanks, and have fun!
  263.  
  264. --- CUT HERE ---
  265.  
  266. /*
  267.  * S W I P E . C
  268.  *
  269.  * Written:
  270.  *     1/11/92
  271.  *
  272.  * Description: Quick 'n Dirty reader program for SR&D mag stripe card reader.
  273.  *     Reads data from the input port as long as a card is detected in the
  274.  *     card slot. After sampling, the data is dumped to stdout, and may
  275.  *     be redirected to a file if desired.
  276.  *
  277.  * Note: Written for Borland C++ 3.0 - may require changes to compile under
  278.  *     MSC or others. Compile in SMALL model.
  279.  *
  280.  */
  281.  
  282. #include <stdio.h>
  283. #include <conio.h>
  284. #include <process.h>
  285. #include <dos.h>
  286. #include <math.h>
  287. #include <stdlib.h>
  288. #include <assert.h>
  289. #include <string.h>
  290.  
  291. /* timer chip programming register port addresses */
  292. #define COMMAND_REG 0x43
  293. #define CHANNEL0 0x40
  294.  
  295. /* size of sample buffer */
  296. #define MAXSAMPLE 4096
  297.  
  298. typedef unsigned char byte;
  299.  
  300.  
  301. /* global variables */
  302. byte *databuf;  /* buffer for the sampled data */
  303.  
  304. /* interprocess communication data */
  305. byte *bufp;         /* data buffer pointer */
  306. unsigned nsamp;     /* number of samples to be made */
  307. unsigned port;      /* input port address */
  308. int enab=0;         /* flag to enable/disable sampling */
  309. int start=0;        /* flag indicating that sampling has begun */
  310.  
  311. /* ISR prototype */
  312. extern void interrupt shand(void);
  313.  
  314.  
  315.  
  316. void program_timer(int channel, unsigned count)
  317. /*
  318.  * P R O G R A M _ T I M E R
  319.  *
  320.  * Description: Programs the given count value into the specified channel of
  321.  *     the IBM 825x timer chip. Channel 0 is the time-of-day-clock interrupt;
  322.  *     channel 2 is the speaker pulser.
  323.  *
  324.  * Parameter:
  325.  *     channel (in) - Channel to be programmed.
  326.  *     count (in) - Count value with which to program timer chip.
  327.  *
  328.  */
  329. {
  330.  
  331.     outportb(COMMAND_REG, 0x36);  /* set up for reprogramming */
  332.     outportb(CHANNEL0 + channel, count & 0xff);  /* lo byte first */
  333.     outportb(CHANNEL0 + channel, count >> 8);  /* then hi byte */
  334. }
  335.  
  336. void sample_data(int count)
  337. /*
  338.  * S A M P L E _ D A T A
  339.  *
  340.  * Description: Sets up for data collection from the printer port using
  341.  *     the SHAND interrupt service routine (see SWIPEISR.ASM). This routine
  342.  *     reprograms the timer chip for the desired sampling rate, sets up
  343.  *     the interprocess communication area, and starts the sampling process.
  344.  *     The actual sampling is done in the SHAND procedure. This routine
  345.  *     waits until sampling has been completed before returning.
  346.  *
  347.  */
  348. {
  349. void interrupt (*oldhand)(void);  /* pointer to old interrupt vector */
  350.  
  351.     /* save old interrupt vector */
  352.     oldhand = getvect(0x1c);
  353.  
  354.     /* clear enable flag */
  355.     enab = 0;
  356.     start = 0;
  357.  
  358.     /* install new vector */
  359.     setvect(0x1c, shand);
  360.  
  361.     /* set up interprocess communications area */
  362.     nsamp = 0;
  363.     bufp = databuf;
  364.     port = 0x279;  /* address of printer status register */
  365.  
  366.     cprintf("Sampling at %fHz (= %fms)....",
  367.        1193180.0 / (float)count, (float)count / 1193.18);
  368.  
  369.     /* reprogram timer chip */
  370.     program_timer(0, count);
  371.  
  372.     /* enable sampling */
  373.     enab = 1;
  374.  
  375.     /* wait until sampling is completed */
  376.     while (enab) ;
  377.  
  378.     /* restore standard timing value */
  379.     program_timer(0, 0);
  380.  
  381.     /* reinstall old handler vector */
  382.     setvect(0x1c, oldhand);
  383.  
  384.     cprintf(" completed.\r\n");
  385.  
  386. }
  387.  
  388.  
  389. void main()
  390. {
  391. unsigned i;
  392.  
  393.     /* allocate memory */
  394.     databuf = calloc(MAXSAMPLE, sizeof(byte));
  395.     assert (databuf != NULL);
  396.  
  397.     cprintf("Press <ENTER> when ready to swipe card:");
  398.     getchar();
  399.     sample_data(12);  /* This works out to about a 100kHz sampling rate  */
  400.  
  401.     cprintf("Sampling completed, %u samples total.\r\n", nsamp);
  402.     cprintf("Press <ENTER> to dump data.\r\n\r\n");
  403.     getchar();
  404.  
  405.     /* dump data to stdout */
  406.     for (i=0; i<nsamp; ++i)
  407.     if (kbhit())
  408.         break;
  409.     else
  410.         printf("%u\n", databuf[i]);
  411.  
  412.     free (databuf);
  413.  
  414. }
  415.  
  416. --- CUT HERE ---
  417.  
  418. ;
  419. ; S W I P E I S R . A S M
  420. ;
  421. ; Interrupt Service Routine to sample swipe reader.
  422. ;
  423.  
  424. _TEXT   segment byte public 'CODE'
  425. DGROUP    group    _DATA,_BSS
  426.     assume    cs:_TEXT,ds:DGROUP,ss:DGROUP
  427. _TEXT    ends
  428.  
  429. _DATA    segment word public 'DATA'
  430. ; Nuthin' in here!
  431. _DATA   ends
  432.  
  433. _BSS    segment word public 'BSS'
  434. ; Nuthin' in here either!
  435. _BSS    ends
  436.  
  437. _TEXT    segment    byte public 'CODE'
  438. ;
  439. ; S H A N D
  440. ;
  441. ; Description: Sample interrupt handler for timer extension interrupt 0x1c.
  442. ;
  443. ; Note: Assumes that the /CARD DETECT line appears on bit 7 of the input
  444. ;     port. This bit corresponds to pin 11 on the standard PC printer port.
  445. ;     Also, the PC printer port card inverts the signal on this pin; thus,
  446. ;     bit 7 is *set* when a card is in the reader, even though /CARD DETECT
  447. ;     is an active low signal.
  448. ;
  449. _shand    proc    far
  450.     push    ax
  451.     push    bx
  452.     push    dx
  453.     push    ds
  454.     push    si
  455.     push    di
  456.     push    bp
  457.     mov    bp,DGROUP
  458.     mov    ds,bp
  459.  
  460.         cmp     word ptr DGROUP:_enab, 0                ; Are we turned on?
  461.         je      ciao                                    ; Nope - goodbye!
  462.  
  463.         mov     dx, word ptr DGROUP:_port               ; Get port address
  464.         cmp     word ptr DGROUP:_start, 0               ; Has sampling begun?
  465.         jne     doit                                    ; Yup - hop to it!
  466.  
  467. ;
  468. ; Sampling is enabled but has not actually begun because no card has yet been
  469. ;     detected in the slot of the reader. Check to see if a card has arrived
  470. ;     yet and, if it has, set the flag to indicate that sampling should begin.
  471. ;
  472.         in      al, dx                                  ; sample port
  473.         test    al, 80h                                 ; card detected?
  474.         jz      ciao                                    ; nope - later!
  475.  
  476.         mov     word ptr DGROUP:_start, 1               ; card's there,
  477.                                                         ; start reading it
  478.         jmp     saveit
  479. ;
  480. doit:
  481.         in      al, dx                                  ; Read the port
  482.         test    al, 80h                                 ; card detect bit set?
  483.         jz      disable                                 ; if not, quit
  484. ;
  485. ; Data is still valid; get buffer pointer and save the data
  486. ;
  487. saveit:
  488.         mov     bx,word ptr DGROUP:_bufp                ; get addr. to write
  489.         mov     byte ptr [bx],al                        ; save sampled value
  490.         inc     word ptr DGROUP:_bufp                   ; and bump the ptr
  491.  
  492.         inc     word ptr DGROUP:_nsamp                  ; update sample count
  493.         jmp     ciao                                    ; and skeedaddle
  494.  
  495. disable:
  496.         mov     word ptr DGROUP:_enab,0                 ; card no longer
  497.                                                         ; detected - disable
  498.                                                         ; sampling
  499. ciao:
  500.         pop     bp                                      ; restore context
  501.     pop    di
  502.     pop    si
  503.     pop    ds
  504.     pop    dx
  505.     pop    bx
  506.     pop    ax
  507.     iret    
  508. _shand    endp
  509. _TEXT    ends
  510.  
  511. _DATA    segment word public 'DATA'
  512. ;s@      label   byte
  513. _DATA    ends
  514.         extrn   _nsamp:word
  515.     extrn    _port:word
  516.     extrn    _bufp:word
  517.     extrn    _enab:word
  518.         extrn   _start:word
  519. _TEXT    segment    byte public 'CODE'
  520.     extrn    _inportb:near
  521. _TEXT    ends
  522.     public    _shand
  523.     end
  524.  
  525.  
  526.                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  527.                 d  a  t  a       c  o  n  t  r  o  l       I.             
  528.                 c o n t r o l         t e a m         u s h q 
  529.                 t e l c o ' s     s h a k e    i n    f e a r
  530.                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  531. < Advertisment added using -=Bad Ad=- 1.91 by Troed/Sync. BBS: +46-451-91002 >
  532.